// JavaScript Document
var zTree;
var demoIframe;

var setting = {
	view: {
		dblClickExpand: false,
		showLine: true,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	callback: {
		beforeClick: function(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("tree");
			if (treeNode.isParent) {
				zTree.expandNode(treeNode);
				return false;
			} else {
				demoIframe.attr("src",treeNode.file + ".html");
				return true;
			}
		}
	}
};

var zNodes =[
	{id:1, pId:0, name:"管理员", open:true},
	{id:101, pId:1, name:"管理员1", file:"core/standardData"},
	{id:102, pId:1, name:"管理员2", file:"core/simpleData"},
	{id:103, pId:1, name:"管理员3", file:"core/noline"},

	{id:2, pId:0, name:"操作员", open:false},
	{id:201, pId:2, name:"操作员1", file:"excheck/checkbox"},
	{id:206, pId:2, name:"操作员2", file:"excheck/checkbox_nocheck"},
	{id:207, pId:2, name:"操作员3", file:"excheck/checkbox_chkDisabled"},
	{id:208, pId:2, name:"操作员4", file:"excheck/checkbox_halfCheck"},
	{id:202, pId:2, name:"操作员5", file:"excheck/checkbox_count"},
];

$(document).ready(function(){
	var t = $("#tree");
	t = $.fn.zTree.init(t, setting, zNodes);
	demoIframe = $("#testIframe");
	demoIframe.bind("load", loadReady);
	var zTree = $.fn.zTree.getZTreeObj("tree");
	zTree.selectNode(zTree.getNodeByParam("id", 101));

});

function loadReady() {
	var bodyH = demoIframe.contents().find("body").get(0).scrollHeight,
	htmlH = demoIframe.contents().find("html").get(0).scrollHeight,
	maxH = Math.max(bodyH, htmlH), minH = Math.min(bodyH, htmlH),
	h = demoIframe.height() >= maxH ? minH:maxH ;
	if (h < 530) h = 530;
	demoIframe.height(h);
}

